/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.serli.sample.person.model.data;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author serli
 */
public class Person implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID =  8847687019439339999L;
    
    private int id;
    private String firstName = null;
    private String lastName = null;
    private Date birthDate = null;
    private Gender gender = Gender.MALE;

    public Person() {
    }

    public Person(String firstName, String lastName, Date birthDate, Gender gender) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.birthDate = birthDate;
        this.gender = gender;
    }

    public Person(int id, String firstName, String lastName, Date birthDate, Gender gender) {
        this(firstName, lastName, birthDate, gender);
        this.setId(id);
    }

    public int getAge() {

        Calendar bd = Calendar.getInstance();
        bd.setTime(getBirthDate());
        Calendar td = Calendar.getInstance();
        int age = td.get(Calendar.YEAR) - bd.get(Calendar.YEAR);
        if (td.get(Calendar.DAY_OF_YEAR) < bd.get(Calendar.DAY_OF_YEAR)) {
            age--;
        }
        return age;
    }

    public String getFirstName() {
        return this.firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return this.lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Date getBirthDate() {
        return this.birthDate;
    }

    public void setBirthDate(Date birthDate) {
        this.birthDate = birthDate;
    }

    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    public int getId() {
        return id;
    }

    final void setId(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Person [id=" + id + ", firstName=" + firstName + ", lastName="
                + lastName + ", birthDate=" + birthDate + ", gender=" + gender
                + "]";
    }
}
